﻿using System;
using System.Collections.Generic;
using System.IO;
using CSJ2K.Util.IO;

namespace CSJ2K.Jpc.Segments
{
    /// <summary>End of packet header (EPH)</summary>
    /// <comment>
    /// Function: Indicates the end of the packet header for a given packet. This delimits 
    ///      the packet header in the bit stream or in the PPM or PPT marker segments. 
    ///      This marker does not denote the beginning of packet data. If packet headers are 
    ///      not in-bit stream (i.e., PPM or PPT marker segments are used), this marker shall 
    ///      not be used in the bit stream. 
    /// Usage: Shall be used if and only if indicated in the proper COD marker segment 
    ///      (see A.6.1). Appears immediately after a packet header. If EPH markers are 
    ///      required (by signalling in the COD marker segment, see A.6.1), each packet 
    ///      header in any given tile-part shall be postpended with an EPH marker segment. If
    ///      the packet headers are moved to a PPM or PPT marker segments (see A.7.4 and 
    ///      A.7.5), then the EPH markers shall appear after the packet headers in the PPM or
    ///      PPT marker segments.
    /// Length: Fixed
    /// </comment>
    public class EPH : Segment
    {
        public EPH(Stream source)
            : this(source, (Markers)StreamUtil.ReadBUInt16(source)) { }
        public EPH(Stream source, Markers marker)
            : base(source, marker, false)
        {
            if (marker != Markers.EPH) throw (new ApplicationException("Attempting to create segment of the wrong type."));
        }
    }
}
